<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\massage\model;

class Queue extends \app\BaseModel
{
    protected $name = "massage_queue_list";
    public function dataAdd($data)
    {
        $res = $this->insert($data);
        return $res;
    }
    public function dataUpdate($dis, $data)
    {
        $res = $this->where($dis)->update($data);
        return $res;
    }
    public function dataList($dis, $page)
    {
        $data = $this->where($dis)->order("status desc,id desc")->paginate($page)->toArray();
        return $data;
    }
    public function dataInfo($dis)
    {
        $data = $this->where($dis)->find();
        return !empty($data) ? $data->toArray() : [];
    }
    public function addQueue($order_id, $type, $uniacid, $refund_price = 0, $refund_user = 0, $text = "", $refund_type = 1, $is_mobile = 1, $is_admin = 1)
    {
        $find = $this->where(["order_id" => $order_id, "type" => $type])->find();
        if(!empty($find)) {
            return false;
        }
        $insert = ["order_id" => $order_id, "type" => $type, "uniacid" => $uniacid, "refund_price" => $refund_price, "refund_user" => $refund_user, "text" => $text, "refund_type" => $refund_type, "is_mobile" => $is_mobile, "is_admin" => $is_admin];
        $res = $this->dataAdd($insert);
        return $res;
    }
    public function queueDo($type)
    {
        $uniacid = 666;
        $key = "queueDo12" . $type;
        incCache($key, 1, $uniacid, 30);
        if(getCache($key, $uniacid) == 1) {
            $data = $this->where(["type" => $type, "status" => 1])->order("id desc")->limit(5)->select()->toArray();
            $refund_model = new RefundOrder();
            if(!empty($data)) {
                foreach ($data as $v) {
                    if($v["type"] == 1) {
                        $res = $refund_model->passOrderData($v["order_id"], $v["refund_price"], 2, $v["refund_user"], $v["text"], $v["refund_type"], $v["is_mobile"], $v["is_admin"]);
                    }
                    if($res) {
                        $this->dataUpdate(["id" => $v["id"]], ["status" => 2]);
                    } else {
                        $update = [];
                        if($v["times"] == 2) {
                            $update["status"] = 3;
                        }
                        $update["times"] = $v["times"] + 1;
                        $this->dataUpdate(["id" => $v["id"]], $update);
                    }
                }
            }
        }
        decCache($key, 1, $uniacid);
        return true;
    }
}

?>